package models

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	GoodsTitle string  `gorm:"type:varchar(50);not null;index;comment:商品标题"`
	GoodsDesc  string  `gorm:"type:varchar(255);not null;comment:商品描述"`
	GoodsCover string  `gorm:"type:varchar(255);not null;comment:商品图片"`
	GoodsPrice float64 `gorm:"type:decimal(10,2);not null;comment:商品价格"`
	GoodsStock int     `gorm:"type:int;not null;default:0;comment:商品库存"`
	Status     int     `gorm:"type:tinyint(1);not null;default:0;comment:商品状态:0-下架,1-上架"`
}

func (g *Goods) Create() error {
	return DB.Create(&g).Error
}

func (g *Goods) Detail(id int) error {
	return DB.Where("id = ?", id).First(&g).Error
}

func (g *Goods) Update() error {
	return DB.Updates(&g).Error
}
